package com.zdxk.msgPush.common.util;

import com.zdxk.msgPush.common.config.ServiceConfig;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.FileSystemResource;

import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

public class LoadYmlConfgUtil {

    public static Map<String,String> loadServiceConfig(String congFilePath){
        String path = ServiceConfig.class.getClassLoader().getResource(congFilePath).getPath();
        YamlPropertiesFactoryBean yamlMapFactoryBean = new YamlPropertiesFactoryBean();
        yamlMapFactoryBean.setResources(new FileSystemResource(path));
        Properties properties = yamlMapFactoryBean.getObject();
        Enumeration<?> enumeration = properties.propertyNames();
        Map<String,String> temp = new ConcurrentHashMap<>();
        while (enumeration.hasMoreElements()) {
            String name = (String) enumeration.nextElement();
            temp.put(name, properties.getProperty(name));
        }
        return temp;
    }
}
